﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using AppManager.Model;
using AutoMapper;
using AppManager.DomainModel;

namespace AppManager.Background
{
    /// <summary>
    ///     automapper中排除那些屬性是關鍵
    /// </summary>
    public class Sys_MenuProfile : Profile
    {
        protected override void Configure()
        {
            //前面的后面的转化
            var map1 = CreateMap<Sys_Menu, Sys_MenuEidtModel>();

            map1.ConstructUsing(s => new Sys_MenuEidtModel
            {
                Flag = s.Flag,
                Id = s.Id,
                Link = s.Link?.TrimEnd('/')?.TrimStart('/'),
                Name = s.Name,
                ParentId = s.ParentId
            });


            var map2 = CreateMap<Sys_MenuEidtModel, Sys_Menu>();
            map2.ConstructUsing(s => new Sys_Menu
            {
                Flag = s.Flag,
                Id = s.Id,
                Link = s.Link?.TrimEnd('/')?.TrimStart('/'),
                Name = s.Name
            });

            var map3 = CreateMap<Sys_Menu, MenuListModel>();
            map3.ConstructUsing(s => new MenuListModel()
            {
                Text = s.Name,
                Value = s.Id.ToString(),
                Childs = Mapper.Map<List<MenuListModel>>(s.Children)
            });

            var map4 = CreateMap<Sys_Menu, SidebarMenu>();
            map4.ConstructUsing(s => new SidebarMenu()
            {
                Url = s.Link?.TrimEnd('/')?.TrimStart('/'),
                Name = s.Name,
                Childs = Mapper.Map<List<SidebarMenu>>(s.Children),
            });

        }
    }
}